import jdk.nashorn.internal.runtime.regexp.joni.Config;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

class UserNameException extends Exception {
    public UserNameException(String message) {
        super(message);
    }
}

class PasswordException extends Exception {
    public PasswordException(String message) {
        super(message);
    }
}

class LogIn {
    private String userName = "admin";
    private String password = "123456";
    public void loginInfo (String userName, String password) throws UserNameException,

            PasswordException {
        if (!this.userName.equals(userName)) {
            throw new UserNameException("用户名错误");
        }
        if (!this.password.equals(password)) {
            throw new PasswordException("密码错误");
        }
        System.out.println("登陆成功");
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名");
        String name = scanner.nextLine();
        System.out.println("请输入密码");
        String password = scanner.nextLine();
        try {
            LogIn logIn = new LogIn();
            logIn.loginInfo(name,password);
        }catch (UserNameException e){
            e.printStackTrace();
        }catch (PasswordException e){
            e.printStackTrace();
        }
    }
}


public class test {
    public static void main3(String[] args) {
        int[] arr = {1, 2, 3};
        try {
            System.out.println("before");
            arr = null;
            System.out.println(arr[100]);
            System.out.println("after");

        } catch (NullPointerException e) { // 永远都捕获执行到
            e.printStackTrace();
        } catch (Exception e) { // Exception可以捕获到所有异常
            e.printStackTrace();
        }
        System.out.println("after try catch");
    }


    public static void main2(String[] args) {
        int[] arr = new int[]{1, 2, 3};
        try {
            System.out.println("before");
            //arr = null;
            System.out.println(arr[100]);
        } catch (NullPointerException e) {
            System.out.println("这是一个空指针异常");
            e.printStackTrace();
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("这是一个数组越界异常");
            e.printStackTrace();
        } finally {
            System.out.println("after");
        }
    }

    public static void main1(String[] args) {
        try {
            int[] array = {1, 2, 3};
            System.out.println(array[3]); // 此处会抛出数组越界异常
        } catch (NullPointerException e) { // 捕获时候捕获的是空指针异常--真正的异常无法被捕获到
            e.printStackTrace();
        }
        System.out.println("后序代码");
    }
}
